package src.com.hpu.parser;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.hpu.bean.OptionalClass;

/**
 * 任选课解析器
 * @author Administrator
 *
 */
public class OptionalClassParser{

	public List<OptionalClass> parse(String parseString) {
		List<OptionalClass> optionalClasses=new ArrayList<>();
		try {
			JSONArray array=new JSONArray(parseString);
			String name = "", classNumber = "";
			for (int i = 0; i < array.length(); i++) {
				JSONArray array2=new JSONArray(array.getString(i));
				for(int j=0;j<array2.length();j++){
					JSONObject obj=array2.getJSONObject(j);
					classNumber=obj.getString("id");
					name=obj.getString("name");
					optionalClasses.add(new OptionalClass(name, classNumber, (i+1)+""));
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	
		return optionalClasses;
	}
}
